<template>
    <div>当前鼠标位置</div>
    <div>x: {{ mouse.x }}</div>
    <div>y: {{ mouse.y }}</div>

    <div>当前点击次数{{ count }}</div>
    <button @click="add">点我加次数</button>
</template>

<script setup>
import { onMounted, onUnmounted, reactive, ref } from 'vue';

const mouse = reactive({
    x: 100,
    y: 100
})
const changeMouse = (e) => {
    mouse.x = e.clientX
    mouse.y = e.clientY
}
onMounted(() => {
    document.addEventListener('mousemove', changeMouse)
})
// 销毁后的生命周期
onUnmounted(() => {
    document.removeEventListener('mousemove', changeMouse)
})



let count = ref(0)
const add = () => {
    count.value++
}

</script>